package com.xingfudazi.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xingfudazi.app.domain.AppMember;
import com.xingfudazi.app.service.IAppMemberService;
import com.xingfudazi.common.annotation.Log;
import com.xingfudazi.common.core.controller.BaseController;
import com.xingfudazi.common.core.domain.AjaxResult;
import com.xingfudazi.common.core.page.TableDataInfo;
import com.xingfudazi.common.enums.BusinessType;
import com.xingfudazi.common.utils.SecurityUtils;
import com.xingfudazi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 会员Controller
 * 
 * @author ruoyi
 * @date 2024-06-21
 */
@RestController
@RequestMapping("/app/member")
public class AppMemberController extends BaseController
{
    @Autowired
    private IAppMemberService appMemberService;

    /**
     * 查询会员列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppMember appMember)
    {
        startPage();
        List<AppMember> list = appMemberService.selectAppMemberList(appMember);
        return getDataTable(list);
    }

    /**
     * 导出会员列表
     */
    @Log(title = "会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppMember appMember)
    {
        List<AppMember> list = appMemberService.selectAppMemberList(appMember);
        ExcelUtil<AppMember> util = new ExcelUtil<AppMember>(AppMember.class);
        util.exportExcel(response, list, "会员数据");
    }

    /**
     * 获取会员详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appMemberService.selectAppMemberById(id));
    }


    /**
     * 获取会员详细信息
     */
    @GetMapping()
    public AjaxResult getInfo()
    {
        return success(appMemberService.selectAppMemberById(SecurityUtils.getUserId()));
    }


    /**
     * 新增会员
     */
    @Log(title = "会员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppMember appMember)
    {
        return toAjax(appMemberService.insertAppMember(appMember));
    }

    /**
     * 修改会员
     */
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppMember appMember)
    {
        return toAjax(appMemberService.updateAppMember(appMember));
    }

}
